<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>deliver</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/main.css"/>
    <script src="/layui/layui.js"></script>
    <script src="/js/jquery.1.8.3.min.js"></script>

</head>
<body>

<div th:include="/common/courierHead :: head"></div>

<div  class="content" style="padding: 10px">



    <div class="demoTable">
        搜索ID：
        <div class="layui-inline">
            <label><input class="layui-input" name="id" id="demoReload" autocomplete="off"  placeholder="输入id"></label>
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
    </div>

    <table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>


    <script src="/layui/layui.all.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script type="text/javascript" >
        layui.use('table', function(){
            var table = layui.table;

            //方法级渲染
            table.render({
                elem: '#LAY_table_user'
                ,url: 'findAllDeliverAPackageByCourierSelf'
                ,cols: [
                    [
                        {checkbox: true, fixed: true}
                        // ,{field:'id', title: 'ID', sort: true, fixed: true}
                        ,{field:'no', title: '单号', sort: true, fixed: true}
/*                        ,{field:'sendName', title: '寄件人'}
                        ,{field:'sendAddress', title: '寄件人地址'}
                        ,{field:'sendPhone', title: '寄件人电话'}*/
                        ,{field:'receiptName', title: '收件人'}
                        ,{field:'receiptAddress', title: '收件人地址'}
                        ,{field:'receiptPhone', title: '收件人电话'}
                        ,{field:'description', title: '客户留言'}
                        ,{field:'state', title: '状态'}
                        ,{field:'right', title: '操作', align:'center', toolbar:'#barDemo', width:200}
                    ]
                ]
                ,id:'testReload'
                ,page: true
                ,height: 480
                ,done: function () {
                    $("[data-field='state']").children().each(function () {
                        if ($(this).text()=='1'){
                            $(this).text("等待揽收")
                        }else if($(this).text()=='2'){
                            $(this).text("运输中")
                        }else if($(this).text()=='3'){
                            $(this).text("派件中")
                        }else if($(this).text()=='-1'){
                            $(this).text("订单取消")
                        }else if($(this).text()=='-2'){
                            $(this).text("取件失败")
                        }else if($(this).text()=='-3'){
                            $(this).text("派送失败")
                        }else if($(this).text()=='0'){
                            $(this).text("派件成功")
                        }
                    });
                }
            });

            var $ = layui.$, active = {
                reload: function(){
                    var demoReload = $('#demoReload');
                    layer.msg('单号：'+demoReload.val()+' 的查看操作');
                    //执行重载
                    table.reload('testReload', {
                        // url:"findAPackageById?pid="+demoReload.val(),
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            key: {
                                id: demoReload.val()
                            }
                        }
                    });
                }
            };
            $('.content .demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            //监听工具条
            table.on('tool(user)', function(obj){
                var data = obj.data;
                if(obj.event === 'deliverOk'){
                    layer.msg('单号：'+ data.no + ' 的查看操作');
                    layer.confirm('确定派件吗？', function(index){
                        window.location.href="/courier/deliverPackageOK?packageId="+data.id;
                    });
                } else if(obj.event === 'deliverNo'){
                    layer.confirm('确定派件失败吗？', function(index){
                        window.location.href="/courier/deliverPackageNO?packageId="+data.id;
                    });
                }
            });
        });
    </script>

    <script type="text/html" id="barDemo">
        {{# if(d.state == '3'){ }}
        <a class=" layui-btn layui-btn-xs" lay-event="deliverOk">确认派件</a>
        <a class=" layui-btn-primary layui-btn-xs" lay-event="deliverNo">派件失败</a>
        {{# }else if(d.state== '0'){ }}
        <!--        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="deliverNo">派件失败</a>-->
        已经派送成功
        {{# }else{ }}
        <!--        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="deliverOk">确认派件</a>-->
        与你无瓜
        {{# } }}
    </script>
</div>

<div th:include="/common/footer :: footer"></div>

</div>


<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function(){
        var element = layui.element;

        //…
    });
</script>
</body>
</html>